package com.example.borui.partpositionproject.simple.utils;

import android.content.Context;
import android.util.DisplayMetrics;

import com.example.borui.partpositionproject.simple.bean.DataBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by borui on 2017/9/29.
 */

public class Utils {

    public static List<DataBean> buildSimpleDatas(){
        List<DataBean> dataBeans = new ArrayList<>();
        DataBean dataBean1 = new DataBean();
        dataBean1.setCluster(true);
        List<DataBean> dataChildBeans1 = new ArrayList<>();
        for(int j = 1; j < 6; j++){
            DataBean dataChildBean1 = new DataBean();
            int childType = j % 5;
            dataChildBean1.setTextContent("第五个分类");
            dataChildBean1.setCluster(true);
            dataChildBeans1.add(dataChildBean1);

            if(childType == 0){
                childType = 5;
            }

            dataChildBean1.setType(childType);

            if(childType == 5){
                dataChildBean1.setCluster(true);
                List<DataBean> dataChildBeans = new ArrayList<>();
                for(int k = 1; k < 4; k++){
                    DataBean dataChildBean = new DataBean();
                    int childType1 = k % 5;
                    dataChildBean.setType(childType1);
                    dataChildBean.setTextContent("第五个分类中的第五个分类");
                    dataChildBean.setCluster(true);
                    dataChildBeans.add(dataChildBean);
                }
                dataChildBean1.setDataChildBeans(dataChildBeans);
            }else{
                dataChildBean1.setCluster(false);
            }
        }
        dataBean1.setDataChildBeans(dataChildBeans1);
        dataBean1.setType(5);
        dataBeans.add(dataBean1);

        for(int i = 1; i < 400; i++){
            DataBean dataBean = new DataBean();
            int type = i % 5;
            if(type == 0){
                type = 5;
            }
            if(type == 5){
                dataBean.setCluster(true);
                List<DataBean> dataChildBeans = new ArrayList<>();
                for(int j = 1; j < 4; j++){
                    DataBean dataChildBean = new DataBean();
                    int childType = j % 5;
                    dataChildBean.setType(childType);
                    dataChildBean.setTextContent("第五个分类");
                    dataChildBean.setCluster(true);
                    dataChildBeans.add(dataChildBean);
                }
                dataBean.setDataChildBeans(dataChildBeans);
            }else{
                dataBean.setCluster(false);
            }
            dataBean.setType(type);
            dataBeans.add(dataBean);
        }
        return dataBeans;
    }

    /**
     * 得到手机屏幕宽高数组
     */
    public static int[] getScreenSize(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        dm = context.getApplicationContext().getResources().getDisplayMetrics();
        int screenWidth = dm.widthPixels;
        int screenHeigh = dm.heightPixels;
        int[] xy = new int[]{screenWidth, screenHeigh};
        return xy;
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 dip 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
